﻿using MyUi_WPF_Controls.TextBoxCtr.Base;
using Prism.Commands;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Media;

namespace MyUi_WPF_Controls.TextBoxCtr
{
    public class IconTextBoxCtr : IconTextBoxBase
    {
        public enum IconPlacementEnum
        {
            Left,
            Right,
            In,
        }

        static IconTextBoxCtr()
        {
            DefaultStyleKeyProperty.OverrideMetadata(typeof(IconTextBoxCtr), new FrameworkPropertyMetadata(typeof(IconTextBoxCtr)));
        }

        #region 事件定义

        public static readonly RoutedEvent EnterKeyClickEvent = EventManager.RegisterRoutedEvent("EnterKeyClick",
            RoutingStrategy.Bubble, typeof(RoutedPropertyChangedEventHandler<object>), typeof(IconTextBoxCtr));

        public event RoutedPropertyChangedEventHandler<object> EnterKeyClick
        {
            add
            {
                this.AddHandler(EnterKeyClickEvent, value);
            }
            remove
            {
                this.RemoveHandler(EnterKeyClickEvent, value);
            }
        }

        protected virtual void OnEnterKeyClick(object oldValue, object newValue)
        {
            RoutedPropertyChangedEventArgs<object> arg =
                new RoutedPropertyChangedEventArgs<object>(oldValue, newValue, EnterKeyClickEvent);
            this.RaiseEvent(arg);
        }
        #endregion

        #region 依赖属性

        #region Path相关属性

        public static readonly DependencyProperty IconPlacementProperty = DependencyProperty.Register("IconPlacement"
            , typeof(IconPlacementEnum), typeof(IconTextBoxCtr));
        /// <summary>
        /// 文本输入框的图标显示位置
        /// </summary>
        public IconPlacementEnum IconPlacement
        {
            get { return (IconPlacementEnum)GetValue(IconPlacementProperty); }
            set { SetValue(IconPlacementProperty, value); }
        }

        public static readonly DependencyProperty IconColorProperty = DependencyProperty.Register("IconColor"
            , typeof(Brush), typeof(IconTextBoxCtr));
        /// <summary>
        /// 图标的颜色
        /// </summary>
        public Brush IconColor
        {
            get { return (Brush)GetValue(IconColorProperty); }
            set { SetValue(IconColorProperty, value); }
        }


        public static readonly DependencyProperty WaterMaktBrushProperty = DependencyProperty.Register("WaterMaktBrush"
           , typeof(Brush), typeof(IconTextBoxCtr));
   
        public Brush WaterMaktBrush
        {
            get { return (Brush)GetValue(WaterMaktBrushProperty); }
            set { SetValue(WaterMaktBrushProperty, value); }
        }

        public static readonly DependencyProperty WaterMaktFontSizeProperty = DependencyProperty.Register("WaterMaktFontSize"
           , typeof(double), typeof(IconTextBoxCtr));

        public double WaterMaktFontSize
        {
            get { return (double)GetValue(WaterMaktFontSizeProperty); }
            set { SetValue(WaterMaktFontSizeProperty, value); }
        }



        public DelegateCommand SearchCommand
        {
            get { return (DelegateCommand)GetValue(_SearchCommandProperty); }
            set { SetValue(_SearchCommandProperty, value); }
        }


        public static readonly DependencyProperty _SearchCommandProperty = DependencyProperty.Register("SearchCommand"
        , typeof(DelegateCommand), typeof(IconTextBoxCtr));

        #endregion

        #endregion

        public IconTextBoxCtr() : base()
        {
            this.KeyUp += IconTextBox_KeyUp;
        }

        private void IconTextBox_KeyUp(object sender, System.Windows.Input.KeyEventArgs e)
        {
            if (e.Key == System.Windows.Input.Key.Enter)
            {
                this.OnEnterKeyClick(null, null);
            }
        }
    }
}
